package com.fs.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.mapper.ReserveMapper;
import com.fs.pojo.Wh_inventory;
import com.fs.service.ReserveService;
import com.fs.vo.Condition;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class ReserveServiceImpl implements ReserveService {

    @Resource
    private ReserveMapper reserveMapper;

    /**
     * 分页并且多条件查询出库存表 wh_inventory
     * @param condition
     * @return
     */
    public Page<Wh_inventory> getReserve(Condition<Wh_inventory> condition) {
        Page<Wh_inventory> page = new Page<>(condition.getPage(), condition.getCount());
        QueryWrapper<Wh_inventory> queryWrapper = new QueryWrapper<>();
        if (condition.getSearch() != null){
            if (condition.getSearch().getWarehouseId() != null){
                queryWrapper.eq("warehouse_id",condition.getSearch().getWarehouseId());
            } else if (condition.getSearch().getProductId() != null) {
                queryWrapper.eq("product_id",condition.getSearch().getProductId());
            } else if (condition.getSearch().getProductName() != null) {
                queryWrapper.eq("product_name",condition.getSearch().getProductName());
            } else if (condition.getSearch().getProductBrand() != null) {
                queryWrapper.eq("product_brand",condition.getSearch().getProductBrand());
            } else if (condition.getSearch().getProductCategory() != null) {
                queryWrapper.eq("product_category",condition.getSearch().getProductCategory());
            }
        }
        reserveMapper.selectPage(page,queryWrapper);
        return page;
    }

    /**
     * 往表格里面添加一条数据
     * @param whInventory
     * @return
     */
    @Override
    public Integer addProduct(Wh_inventory whInventory) {
        return reserveMapper.insert(whInventory);
    }



    /**
     * 根据商品id来修改库存的数量
     * @return
     */
    @Override
    public Integer changeProductQuantity(Wh_inventory whInventory) {
        return reserveMapper.updateById(whInventory);
    }

    /**
     * 根据商品的id删除库存信息
     * @param productId
     * @return
     */
    @Override
    public Integer delProductById(Integer productId) {
        QueryWrapper<Wh_inventory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",productId);
        return reserveMapper.delete(queryWrapper);
    }

    @Override
    public Wh_inventory gerReserveById(Integer id) {
        QueryWrapper<Wh_inventory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        return reserveMapper.selectOne(queryWrapper);
    }




}
